package com.example.proj_kefei.Config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    //新增自动更新
    @Override
    public void insertFill(MetaObject metaObject) {
        //获取当前的系统时间
        Date date = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());

        this.setFieldValByName("createTime",date,metaObject);
        this.setFieldValByName("updateTime",date,metaObject);
        this.setFieldValByName("userStatus",1,metaObject);
    }

    //修改自动更新
    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
